<?php
namespace App\Traits;

use Carbon\Carbon;

trait ResponseTrait
{
    public function responseSuccess($data = [])
    {
        return response()->json([
            'code' => 20000,
            'data' => $data,
            'msg' => 'ok',
            'time' => Carbon::now()->format('Y-m-d H:i:s')
        ])->header('X-CSRF-TOKEN', csrf_token());
    }


    public function responseFailed(String $message = '请求错误', Int $code = 30001)
    {
        return response()->json([
            'msg' => $message,
            'code' => $code,
            'time' => Carbon::now()->format('Y-m-d H:i:s')
        ])->header('X-CSRF-TOKEN', csrf_token());
    }
}